//
//  RecordEditSpectrumCollectionViewCell.m
//  BDD_TWO
//
//  Created by XTW on 2023/6/9.
//

#import "RecordEditSpectrumCollectionViewCell.h"
#import "EZAudioFile.h"
#import "FileManager.h"
#import "LocalRecordModel.h"

@interface RecordEditSpectrumCollectionViewCell()
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UIImageView *tagImageView;
@property (weak, nonatomic) IBOutlet UILabel *tagLabel;
@property (weak, nonatomic) IBOutlet UIView *bgView;

@property (nonatomic, strong) EZAudioFile *audioFile;

@end

@implementation RecordEditSpectrumCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.bgView.layer.masksToBounds = YES;
    [self.bgView setBackgroundColor:ViewBackgroundColor];
    // Initialization code
}

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self = [[[NSBundle mainBundle] loadNibNamed:@"RecordEditSpectrumCollectionViewCell" owner:self options:nil] lastObject];

    }
    return self;
}

- (void)setModel:(LocalRecordModel *)model {
    _model = model;
    if (model.needSaveUrl) {
        self.audioFile = [EZAudioFile audioFileWithURL:model.needSaveUrl];
    } else {
        self.audioFile = [EZAudioFile audioFileWithURL:[NSURL fileURLWithPath:[[FileManager sharedManager] getLocalFilePath:model.fileName]]];
    }
    self.timeLabel.text = [NSString stringWithFormat:@"时长：%@", self.audioFile.formattedDuration];
    if (model.isSelected && !self.onlyOneData) {
        self.bgView.layer.borderWidth = 1.0f;
        self.bgView.layer.borderColor = rgba(236, 94, 101, 1).CGColor;
    } else {
        self.bgView.layer.borderWidth = 0;
    }
}

- (void)setIndexRow:(NSInteger)indexRow {
    _indexRow = indexRow;
    self.tagLabel.text = [NSString stringWithFormat:@"%ld",indexRow+1];
}

- (void)setOnlyOneData:(BOOL)onlyOneData {
    _onlyOneData = onlyOneData;
    self.tagLabel.hidden = onlyOneData;
    self.tagImageView.hidden = onlyOneData;
    
}
@end
